<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Happy ERP</title>

    <script type="text/javascript">
      Ext.onReady(function(){
        var Tree = Ext.tree;
        var treeLoader = new Tree.TreeLoader({dataUrl:'/test/getTreeData'});
        var tree = new Tree.TreePanel({
          useArrows: true,
          autoScroll: true,
          animate: true,
          enableDD: true,
          containerScroll: true,
          xtype: 'container',
          // auto create TreeLoader
          loader: treeLoader,
          //dataUrl: '/test/getTreeData',
          root: {
            nodeType: 'async',
            text: 'Products',
            draggable: false,
            id: 0
          }
        });
        //定义，如何子节点展开时的数据导入。
        tree.on('beforeload',
        function(node){
          tree.loader.dataUrl='/test/getTreeData?node='+node.id; //定义子节点的Loader
        });
        
        /*tree.on('dblclick', function() {
          var selectedNode = tree.getSelectionModel().getSelectedNode();
          //debugger;
          var categorySet = new Ajax.Request('/category/getCategoryNodeInfo?id='+selectedNode.id, {method: 'get', onComplete:setCategoryInfo});
        });*/
        //右键菜单
        var productRightMenu = Ext.create('Ext.menu.Menu', {
          id: 'product_right_menu',
          items: [
            Ext.create('Ext.menu.Item', {
              text: '添加'
            }),
            Ext.create('Ext.menu.Item', {
              text: '删除'
            }),
            Ext.create('Ext.menu.Item', {
              text: '更新'
            }),
            Ext.create('Ext.menu.Item', {
              text: '刷新'
            })
          ]});
        tree.on("contextmenu",function(node,e){
          e.preventDefault();
          node.select();
          productRightMenu.showAt(e.getXY());
        });
        // render the tree
        tree.render('tree-div');
        tree.getRootNode().expand();

      })
    </script>
  </head>
  <body>    
    <div id="tree-div"></div>
  </body>
</html>
